import numpy as np
import matplotlib.pyplot as plt
from src.common.processedmeasurement import ProcessedMeasurement
import logging
import os
from bins.vehicleParams import VehicleParams
from bins.vehiclelogger import VehicleStateLogger
from src.mainControl import MainControl
import threading
import time

# 设置日志记录
timestamp_str = time.strftime("%Y-%m-%d_%H_%M_%S", time.localtime())
log_file = "./log/" + timestamp_str + '.log'
logging.basicConfig(level=logging.DEBUG,
    format='%(asctime)s - %(levelname)s - %(message)s',
    handlers=[
        logging.FileHandler(log_file),  # 将日志写入至文件 "example.log"
        logging.StreamHandler()              # 同时输出日志至控制台
    ])

folder_name = "Car_state_file"
folder_path = f"./{folder_name}"
if not os.path.exists(folder_path):
    os.makedirs(folder_path)
file_path = os.path.join(folder_path, f"target_list_{timestamp_str}.txt")

if __name__ == '__main__':
    logging.info("Start the process.")
    record = VehicleStateLogger()
    record.load_file("./record/" + timestamp_str + ".json")
    main_process = MainControl()
    vehicle = VehicleParams()
    vehicle.load_vehicle_params()
    if main_process.init():
        logging.info("Main process initialized.")
    else:
        logging.error("Main process failed to initialize.")
        exit(1)
    main_process.run()
